package com.xiaotu.spider.guduo.pipeline;

import org.springframework.stereotype.Component;

import com.xiaotu.common.model.TVGuDuoArticleModel;
import com.xiaotu.common.model.TVGuDuoPlayModel;
import com.xiaotu.common.util.Constants;
import com.xiaotu.common.util.DataRedisKeyUtils;
import com.xiaotu.spider.APipeline;

import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;

/**
 * @类名 GuDuoPipeline
 * @日期 2017年11月20日
 * @作者 王艳龙
 * @功能 骨朵传媒pipeline
 */

@Component("GuDuoPipeline")
public class GuDuoPipeline extends APipeline
{
    @Override
    protected void doProcess(ResultItems resultItems, Task task)
    {
    	TVGuDuoPlayModel guduo_py = resultItems.get(TVGuDuoPlayModel.class.getName());
        if (guduo_py == null)
            return;
        String key = DataRedisKeyUtils.getKey(Constants.DataRedisKey.GUDUO_PLAY_YYYYMMDD);
    	cacheHandler.hSet(key, guduo_py.getTvId(), guduo_py);
        cacheHandler.setCacheTimeout(key);
        
        TVGuDuoArticleModel guduo_art = resultItems.get(TVGuDuoArticleModel.class.getName());
        if (guduo_art == null)
            return;
        String key_art = DataRedisKeyUtils.getKey(Constants.DataRedisKey.GUDUO_ARTICLE_YYYYMMDD);
    	cacheHandler.hSet(key_art, guduo_art.getTvId(), guduo_art);
        cacheHandler.setCacheTimeout(key_art);
    }

}
